﻿<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>短信快捷回复 10086</title>
    <style>
        body {
            text-align: center;
            padding: 20px;
            font-family: Arial, sans-serif;
            background-color: #f5f5f5;
        }
        .loader {
            width: 40px;
            height: 40px;
            border: 4px solid #f3f3f3;
            border-top: 4px solid #007bff;
            border-radius: 50%;
            margin: 20px auto;
            animation: spin 1s linear infinite;
        }
        #manualSection {
            display: none;
            margin-top: 30px;
        }
        .btn {
            padding: 12px 25px;
            font-size: 16px;
            border-radius: 25px;
            cursor: pointer;
            transition: all 0.3s;
        }
        .primary-btn {
            background-color: #007bff;
            color: white;
            border: 2px solid #007bff;
        }
        .secondary-btn {
            background-color: #fff;
            color: #007bff;
            border: 2px solid #007bff;
            margin-left: 10px;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body>
    <h2>短信自动回复系统</h2>
    <div class="loader" id="loader"></div>
    <p id="statusText">正在初始化短信功能...</p>
    
    <div id="manualSection">
        <p>⚠️ 自动发送未成功，请选择操作：</p>
        <button class="btn primary-btn" onclick="sendSMS()">
            重试自动发送
        </button>
        <button class="btn secondary-btn" 
                onclick="location.href='sms:10086?body='+encodeURIComponent('是')">
            手动发送短信
        </button>
    </div>

    <script>
        let isSent = false;
        const statusText = document.getElementById('statusText');
        const manualSection = document.getElementById('manualSection');
        const loader = document.getElementById('loader');

        // 设备检测
        const isIOS = /iPad|iPhone|iPod/.test(navigator.userAgent);
        const isWeChat = /MicroMessenger/.test(navigator.userAgent);

        function buildSMSURI() {
            let bodyContent = encodeURIComponent('是');
            if(isIOS) {
                return `sms:10086;?&body=${bodyContent}`;
            }
            return `sms:10086?body=${bodyContent}`;
        }

        function sendSMS() {
            if(isWeChat) {
                alert('请点击右上角用系统浏览器打开');
                return;
            }

            const smsURI = buildSMSURI();
            try {
                const link = document.createElement('a');
                link.href = smsURI;
                link.style.display = 'none';
                document.body.appendChild(link);
                link.click();
                isSent = true;
                statusText.textContent = '正在跳转到短信应用...';
            } catch (e) {
                showManualSection();
            }
        }

        function showManualSection() {
            loader.style.display = 'none';
            manualSection.style.display = 'block';
            statusText.textContent = '自动发送失败';
        }

        // 初始化流程
        window.addEventListener('load', () => {
            if(isWeChat) {
                statusText.innerHTML = '检测到微信浏览器<br>请使用系统浏览器打开';
                showManualSection();
                return;
            }

            setTimeout(() => {
                if(!isSent) showManualSection();
            }, 3000);

            // 监听页面失去焦点（说明跳转到短信应用）
            window.addEventListener('blur', () => {
                if(isSent) return;
                isSent = true;
                setTimeout(() => {
                    alert('如果短信未发送，请返回页面手动操作');
                }, 1000);
            });

            sendSMS();
        });
    </script>
</body>
</html>